<#assign module="area"/>

<#macro padZero value>
    <#if value?length==1>
    0${value?if_exists}
    <#else>
    ${value?if_exists}
    </#if>
</#macro>
<@override name="header">
</@override>
<@override name="body">

<div class="row">
	<div class="col-xs-12">
		<button id="add-new-area" class="pull-right btn btn-primary"><i class="icon-plus"></i>&nbsp;添加新收费标准</button>
	</div>
</div>

<div class="row query-pad">
	<div class="col-xs-3 input-query" style="padding: 0px;">
		<span>收费标准名称:</span>
		<input type="text" class="form-control form-contb" id="searchName" name="searchName" placeholder="请输入收费标准名称"/>
	    <button id="searchButton" class="pull-right btn btn-primary">&nbsp;查询</button>
	</div>
</div>
<div class="btn-group">
	  <a class="btn btn-default" href="${ctx}/area/list">里程收费</a>
	  <a class="btn btn-default" href="${ctx}/area/weightlist" style="background-color: #EBEBEB">重量收费</a>
	</div>
<div class="row margin-top area_container">
	<#list weightarealist as area>
		<form action="${ctx}/area/saveWeight" class="form-horizontal" method="post">
		<input type="hidden" name="id" value="${area.id}">
		<div class="col-md-12">
			<div class="panel panel-default">
			  <div class="panel-heading">
	              <span class="name_span">${area.name?if_exists}</span>
	              <input type="text" value="${area.name}" name="name" class="name_input" style="width:150px;display:none;" required/>
	              <button type="button" data="${area.id}" class="deleteArea pull-right button button-pill button-flat-caution button-tiny"><span class="glyphicon glyphicon-remove"></span>&nbsp;删除</button>
	           <!--   <button type="button" class="area-add pull-right button button-pill button-flat-action button-tiny"><span class="glyphicon glyphicon-plus"></span>&nbsp;新增重量段</button> -->
	              <button type="button" class="area-edit pull-right button button-pill button-flat-primary button-tiny"><span class="glyphicon glyphicon-edit"></span>&nbsp;修改</button>
	              <button type="button" class="area-save pull-right button button-pill button-flat button-tiny"><span class="glyphicon glyphicon-floppy-disk"></span>&nbsp;保存</button>
	          </div>
			  <div class="panel-body  time_panel_body">
			  	<#if area.chargeStartWeight??>
			  	<#list area.chargeStartWeight?sort_by("cost") as time>
	            <div class="item-length">
						
					<div class="panel-group">
					  <div class="panel panel-default">
					    <div class="panel-heading">
					      <h4 class="panel-title">
					        <a data-toggle="collapse" href="#collapseOne_${time.id}">
							展开
					        </a>
					        <span class="time_button pull-right">
					      		<button type="button" class="pull-right btn btn-default btn-xs time_button_delete">删除</button>
					      		<button type="button" class="pull-right btn btn-default btn-xs time_button_edit">修改</button>
					      		<button type="button" class="pull-right btn btn-default btn-xs time_button_add">添加重量价格</button>
					      	</span>
					      </h4>
					    </div>
					    
					    <div id="collapseOne_${time.id}" class="panel-collapse collapse in">
					      <div class="panel-body">
					      	<table class="table table-condensed table-bordered">
								<tr style="font-size:14px;">
									<th>开始重量(KG)</th>
									<th>结束重量(KG)</th>
									<th>增长价(元)</th>
									<th>操作</th>
								</tr>
								<#if time.chargeWeightDistance??>
									<#assign distancelist=time.chargeWeightDistance />
			  						<#list distancelist as distance>
				  						<tr class="distance_tr">
				  							<#if (distance_index==0)>
				  							<td>0</td>
				  							<#else>
				  							<td><span>${distancelist[distance_index-1].distance}</span><input class="distance_td_distance_start" type="number" required  value="${distancelist[distance_index-1].distance}" style="display:none;" /></td>
				  							</#if>
											<td><span>${distance.distance}</span><input class="distance_td_distance" type="number" required value="${distance.distance}" style="display:none;" /></td>
											<td><span>${distance.money}</span><input class="distance_td_money" type="number" required value="${distance.money}" style="display:none;" /></td>
											<td>
												<a href="javascript:;" class='distance_td_edit'>修改</a>
												<a href="javascript:;" class='distance_td_delete'>删除</a>
											</td>
										</tr>
									</#list>
            					</#if>
							</table>
							<hr/>
							<span class="time_content2">
								超过（<span class="this_qblc">${time.startWeight}</span><input type="number" value="${time.startWeight}" name="chargeStartWeight[${time_index}].startWeight" class="qblc_input bottom_border" style="width:60px;display:none;" required min="0"/>KG）
		                    	以后每<span class="this_djglUnit">${time.addWeight}</span><input type="number" value="${time.addWeight}" name="chargeStartWeight[${time_index}].addWeight" class="djglUnit_input bottom_border" style="width:60px;display:none;" required min="0"/>KG
		                    	（不足<span class="this_djglThresholdt">${time.overWeight}</span><input type="number" value="${time.overWeight}" name="chargeStartWeight[${time_index}].overWeight" class="djglThresholdt_input bottom_border" style="width:60px;display:none;" required min="0"/>KG不计费）
		                    	加收<span class="this_djglCost">${time.cost}</span><input type="number" value="${time.cost}" name="chargeStartWeight[${time_index}].cost" data-name="chargeStartWeight[${time_index}]" class="djglCost_input bottom_border" style="width:60px;display:none;" required min="0"/>元 ； 
		                    	<p></p>
					      	</span>
					      </div>
					    </div>
					    
					  </div>
					</div>
	                
	            </div>
	            
	            </#list>
	            </#if>
	            
	            <h4 class="text-primary">收费说明：</h4>
	            <p class="text-muted">
	        		<span class="memo_span">${area.memo?if_exists}</span>
	        		<textarea class="memo_textarea" cols="100" rows="5" style="display:none;" name="memo">${area.memo?if_exists}</textarea>
	            </p>
			  </div>
			</div>
		</div>
		</form>
	</#list>
	<div style="text-align:center" id="NoData"></div>
</div>
</@override>
<@override name="footer">
<script src="${ctx}/assets/js/weightarea.js"></script>

<script type="text/javascript">
<#if successMessage??>
	$.scojs_message("${successMessage}", $.scojs_message.TYPE_OK);
</#if>
<#if failureMessage??>
	$.scojs_message("${failureMessage}", $.scojs_message.TYPE_ERROR);
</#if>

var dv;
var dvitem
function deleteArea() {
    $.post('${ctx}/area/deleteWeight',{'id':dv},function(data){
            if(data.success){
                $.scojs_message('重量收费标准删除成功', $.scojs_message.TYPE_OK);
                window.location="${ctx}/area/weightlist";//强制刷新
            } else {
                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
            }
    },'json');
}
function deleteAreaNew() {
	window.location="${ctx}/area/weightlist";//强制刷新
}
function deleteAreaItem() {
    $.post('${ctx}/area/deleteitem',{'id':dvitem},function(data){
            if(data.success){
                $.scojs_message('时间段删除成功', $.scojs_message.TYPE_OK);
                window.location="${ctx}/area/weightlist";//强制刷新
            } else {
                $.scojs_message(data.message, $.scojs_message.TYPE_ERROR);
            }
    },'json');
}
$(document).ready(function(){
	
	$(document).on('click','.deleteArea',function(){
          dv = $(this).attr('data');
          var confirm = $.scojs_confirm({
            content: "你真的要删除该计费规则吗？",
            action:deleteArea
          });
          confirm.show();
    });
    
    $(document).on('click','.deleteArea-item',function(){
          dvitem = $(this).attr('data');
          var confirm = $.scojs_confirm({
            content: "你真的要删除该时间段吗？",
            action:deleteAreaItem
          });
          confirm.show();
    });
    
    $(document).on('click','.deleteArea-new',function(){
          dv = $(this).attr('data');
          var confirm = $.scojs_confirm({
            content: "你真的要删除该计费规则吗？",
            action:deleteAreaNew
          });
          confirm.show();
    });
   
    
});
</script>
</@override>
<@extends name="../layout.ftl"/>